﻿#ifndef QLYSWSCONTEXT_H
#define QLYSWSCONTEXT_H

#include <QSize>
#include <QImage>
#include <QVideoFrame>

extern "C" {
#include "libswresample/swresample.h"
#include "libswscale/swscale.h"
#include "libavutil/imgutils.h"
}
class QlySwsContext
{
public:
    QlySwsContext(QSize srcSize, enum AVPixelFormat srcFormat, QSize dstSize, enum AVPixelFormat dstFormat, int flag);
    ~QlySwsContext();

    static bool convert(QVideoFrame &frame, QImage &image);
    static bool convert(QImage &from, AVFrame *pFrame);
    static bool scale(const QImage &inImage, QImage &outImage, double scaleX, double scaleY); //

protected:
    SwsContext * m_pContext;
    QSize m_srcSize;
    QSize m_dstSize;
    AVPixelFormat m_srcFormat;
    AVPixelFormat m_dstFormat;

    int m_flag;

};


enum AVPixelFormat toAVPixelFormat(QImage::Format format);
enum AVPixelFormat toAVPixelFormat(QVideoFrame::PixelFormat format);

#endif // QLYSWSCONTEXT_H
